package com.deloitte.payrollmgtsys.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.deloitte.payrollmgtsys.util.DashboardConstants;

/**
 * Responsible for creating Process Instance view.
 * 
 * @author muwang
 *
 */
@Controller
@RequestMapping("/processInstances")
public class ProcessInstanceController {
	
	/**
	 * List all running Process Instance.
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("")
	public void getAllRunningProcessInstances(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setAttribute("current_page", DashboardConstants.PROC_INST_PAGE);
		request.getRequestDispatcher("/pages/processInstances.jsp").forward(request, response);
	}
	
	/**
	 * List all tasks that belongs to given process instance.
	 * 
	 * @param id
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/{id}/tasks")
	public void getAllTasks(@PathVariable int id, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setAttribute("curProcInstanceId", id);
		request.setAttribute("current_page", DashboardConstants.PROC_INST_TASK_PAGE);
		request.getRequestDispatcher("/pages/processTasks.jsp").forward(request, response);
	}
}
